package com.itheima.web.controller;

import cn.hutool.core.util.NumberUtil;
import com.itheima.web.manager.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    UserManager userManager;

    @GetMapping("/manage/users")
    public ResponseEntity findByPage(
            @RequestParam(value = "page",defaultValue = "1")int pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10")int pageSize){

        return userManager.findByPage(pageNum,pageSize);
    }

    @GetMapping("/manage/users/{userId}")
    public ResponseEntity findUserInfoById(@PathVariable Long userId){
        return userManager.findUserInfoById(userId);
    }

    @GetMapping("/manage/messages")
    public ResponseEntity findMovementByCondition4Page(
            Long uid,
            String state,
            @RequestParam(value = "page",defaultValue = "1")int pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10")int pageSize){

        Integer status = NumberUtil.isInteger(state)?NumberUtil.parseInt(state):null;

        return userManager.findMovementByCondition4Page(uid,status,pageNum,pageSize);
    }

    @GetMapping("/manage/messages/{movementId}")
    public ResponseEntity findMovementById(@PathVariable String movementId){
        return userManager.findMovementById(movementId);
    }


    @GetMapping("/manage/messages/comments")
    public ResponseEntity findMovementComemntByPage(
            @RequestParam(value = "page",defaultValue = "1")int pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10")int pageSize,
            String messageID){
        return userManager.findMovementComemntByPage(pageNum,pageSize,messageID);
    }

    @GetMapping("/manage/videos")
    public ResponseEntity findUserVideoByPage(
            @RequestParam(value = "page",defaultValue = "1")int pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10")int pageSize,
            Long uid){
        return userManager.findUserVideoByPage(pageNum,pageSize,uid);
    }





}
